package com.yuanxin.app.appjob.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;

import com.yuanxin.service.biz.userbasesrv.appobject.UserBaseAO;



public class CheckLoginInterCeptor implements HandlerInterceptor{
    public void afterCompletion(HttpServletRequest arg0,
            HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {
   
    }
 
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
            Object arg2, ModelAndView arg3) throws Exception {
       
    }
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
            Object arg2) throws Exception {
		UserBaseAO currentUser = (UserBaseAO) WebUtils.getSessionAttribute(request, Constant.SESSION_CURRENT_USER);
        if(currentUser==null){
            //用户没有登录
            response.sendRedirect(request.getContextPath()+"/");
            return false;
        }else {
            //用户已经登录
            return true;
        }
    }
}
